package com.attendance.www.hr.service.impl;

import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.attendance.www.hr.beans.OrganizationMainBean;
import com.attendance.www.hr.beans.EmployeeMainBean;
import com.attendance.www.hr.beans.MainQueryJobsBean;
import com.attendance.www.hr.beans.MainQueryOrganizationsBean;
import com.attendance.www.hr.beans.MainQueryUsersBean;
import com.attendance.www.hr.beans.RoleMainBean;
import com.attendance.www.hr.beans.TokenBean;
import com.attendance.www.hr.constant.AppConstant;
import com.attendance.www.hr.dao.mapper.EmployeeMapper;
import com.attendance.www.hr.dao.mapper.MainJobsMapper;
import com.attendance.www.hr.dao.mapper.MainJobsNewMapper;
import com.attendance.www.hr.dao.mapper.MainJobsVersionMapper;
import com.attendance.www.hr.dao.mapper.MainOrganizationsMapper;
import com.attendance.www.hr.dao.mapper.MainOrganizationsNewMapper;
import com.attendance.www.hr.dao.mapper.MainOrganizationsVersionMapper;
import com.attendance.www.hr.dao.mapper.MainUsersMapper;
import com.attendance.www.hr.dao.mapper.MainUsersNewMapper;
import com.attendance.www.hr.dao.mapper.MainUsersVersionMapper;
import com.attendance.www.hr.dao.mapper.RequestInterfaceTaskExtMapper;
import com.attendance.www.hr.dao.mapper.SystemConfigureMapper;
import com.attendance.www.hr.entitys.Employee;
import com.attendance.www.hr.entitys.EmployeeExample;
import com.attendance.www.hr.entitys.MainJobs;
import com.attendance.www.hr.entitys.MainJobsNew;
import com.attendance.www.hr.entitys.MainOrganizations;
import com.attendance.www.hr.entitys.MainOrganizationsNew;
import com.attendance.www.hr.entitys.MainUsers;
import com.attendance.www.hr.entitys.MainUsersNew;
import com.attendance.www.hr.entitys.SystemConfigure;
import com.attendance.www.hr.entitys.SystemConfigureExample;
import com.attendance.www.hr.service.IEmployeeMainService;
import com.attendance.www.hr.service.IMainJobsNewService;
import com.attendance.www.hr.service.IMainJobsService;
import com.attendance.www.hr.service.IMainJobsVersionService;
import com.attendance.www.hr.service.IMainOrganizationsNewService;
import com.attendance.www.hr.service.IMainOrganizationsService;
import com.attendance.www.hr.service.IMainOrganizationsVersionService;
import com.attendance.www.hr.service.IMainService;
import com.attendance.www.hr.service.IMainUsersNewService;
import com.attendance.www.hr.service.IMainUsersService;
import com.attendance.www.hr.service.IMainUsersVersionService;
import com.attendance.www.hr.service.IOrganizationsMainService;
import com.attendance.www.hr.service.IRequestInterfaceTaskService;
import com.attendance.www.hr.service.IRoleMainService;
import com.attendance.www.hr.service.ISystemConfigureService;
import com.attendance.www.hr.utils.HttpRequestMain;
import com.attendance.www.hr.utils.ToolUtils;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service
public class MainServiceImpl implements IMainService {
	
	@Resource
	private EmployeeMapper employeeDao;
	@Resource
	private SystemConfigureMapper systemConfigureDao;
	@Resource
	private MainUsersMapper mainUsersDao;
	@Resource
	private MainUsersNewMapper mainUsersNewDao;
	@Resource
	private MainUsersVersionMapper mainUsersVersionDao;
	@Resource
	private MainOrganizationsMapper mainOrganizationsDao;
	@Resource
	private MainOrganizationsNewMapper mainOrganizationsNewDao;
	@Resource
	private MainOrganizationsVersionMapper mainOrganizationsVersionDao;
	@Resource
	private MainJobsMapper mainJobsDao;
	@Resource
	private MainJobsNewMapper mainJobsNewDao;
	@Resource
	private MainJobsVersionMapper mainJobsVersionDao;
	@Resource
	private RequestInterfaceTaskExtMapper requestInterfaceTaskExtDao;
	@Resource
	private IRequestInterfaceTaskService requestInterfaceTaskService;
	@Resource
	private IMainUsersService mainUsersService;
	@Resource
	private IMainUsersNewService mainUsersNewService;
	@Resource
	private IMainUsersVersionService mainUsersVersionService;
	@Resource
	private IMainJobsService mainJobsService;
	@Resource
	private IMainJobsNewService mainJobsNewService;
	@Resource
	private IMainJobsVersionService mainJobsVersionService;
	@Resource
	private IMainOrganizationsService mainOrganizationsService;
	@Resource
	private IMainOrganizationsNewService mainOrganizationsNewService;
	@Resource
	private IMainOrganizationsVersionService mainOrganizationsVersionService;
	@Resource
	private IEmployeeMainService employeeMainService;
	@Resource
	private IOrganizationsMainService organizationsMainService;
	@Resource
	private IRoleMainService roleMainService;
	@Resource
	private ISystemConfigureService systemConfigureService; 
	
	private Logger log = Logger.getLogger(MainServiceImpl.class);
	
	/**
	 * 请求接口名称
	 */
	private String interfaceName = null;

	/**
	 * 主数据IP地址
	 */
	private String ip = AppConstant.MAIN_IP;
	
	/**
	 * 同步主数据开始日期
	 */
	private Date startDate=null;
	
	/**
	 * 获取配置邮箱人信息
	 */
	private String mailEmployeeNo=AppConstant.MAIN_MAIL_EMPLOYEENO;
	
	/**
	 * 获取系统配置表
	 */
	private SystemConfigure scf=null;
	
	/**
	 * 全量同步主数据
	 */
	@Override
	public void requestMaindata() {
		try {
			List<SystemConfigure> systemConfigureList = systemConfigureDao.selectByExample(new SystemConfigureExample());
			scf = systemConfigureList.get(0);
			
			//设置请求同步主数据开始日期
			startDate=new Date();
			
			//获取机构信息接口
			List<MainOrganizations> mainOrganizationsList = this.queryOrganization();
			//获取岗位信息接口
			List<MainJobs>mainJobsList = this.queryJobs();
			//获取人员信息接口
			List<MainUsers> mainUsersList = this.queryUser();
			
			try {
				//将信息插入到机构表及关系表
				List<OrganizationMainBean> corporationMainBeanList=new ArrayList<OrganizationMainBean>();
				for (int i = 0; i < mainOrganizationsList.size(); i++) {
					MainOrganizations mainOrganizations=new MainOrganizations();
					OrganizationMainBean corporationMainBean=new OrganizationMainBean();
					mainOrganizations=mainOrganizationsList.get(i);
					BeanUtils.copyProperties(corporationMainBean, mainOrganizations);
					corporationMainBeanList.add(corporationMainBean);
				}
				organizationsMainService.saveOrganizationsMain(corporationMainBeanList,1);
			}catch(Exception e) {
				log.error(e.getMessage());
				HttpRequestMain.mailSend("机构信息全量接口", 3, this.getEmployeeList(), scf);
			}
			
			try {
				//将信息插入到岗位表及关系表
				List<RoleMainBean> roleMainBeanList =new ArrayList<RoleMainBean>();
				for(int i=0;i<mainJobsList.size();i++) {
					MainJobs mainJobs=new MainJobs();
					RoleMainBean roleMainBean=new RoleMainBean();
					mainJobs=mainJobsList.get(i);
					BeanUtils.copyProperties(roleMainBean, mainJobs);
					roleMainBeanList.add(roleMainBean);
				}
				roleMainService.saveRoleMain(roleMainBeanList);
			}catch(Exception e) {
				log.error(e.getMessage());
				HttpRequestMain.mailSend("岗位信息全量接口", 3, this.getEmployeeList(), scf);
			}
			
			try {
				//将信息插入到人员表及关系表
				List<EmployeeMainBean> employeeMainBeanList = new ArrayList<EmployeeMainBean>();
				for (int i = 0; i < mainUsersList.size(); i++) {
					MainUsers mainUsers = new MainUsers();
					EmployeeMainBean employeeMainBean = new EmployeeMainBean(); 
					mainUsers = mainUsersList.get(i);
					BeanUtils.copyProperties(employeeMainBean, mainUsers);
					employeeMainBeanList.add(employeeMainBean);
				}
				employeeMainService.saveEmployeeMain(employeeMainBeanList);
			}catch(Exception e) {
				log.error(e.getMessage());
				HttpRequestMain.mailSend("员工信息全量接口", 3, this.getEmployeeList(), scf);
			}	
			//屏蔽 更改次数
			/*SystemConfigure systemConfigure=new SystemConfigure();
			systemConfigure.setSystemConfigureId(1);
			systemConfigure.setTokenCount(1);
			systemConfigureDao.updateByPrimaryKeySelective(systemConfigure);*/
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 增量定时同步主数据
	 */
	@Override
	public void requestMaindataNew(Date attDate) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			List<SystemConfigure> systemConfigureList = systemConfigureDao.selectByExample(new SystemConfigureExample());
			scf = systemConfigureList.get(0);
			
			//设置请求同步主数据开始日期
			startDate=new Date();
			
			//获取上一次请求成功日期
			Date de=requestInterfaceTaskExtDao.selectStartDateByNotToken();
			if(de==null) {
				de=new Date();
			}
			if(attDate!=null) {
				de = attDate;
			}
			//格式日期
			String dateTime = sdf.format(de);
			
			List<MainOrganizationsNew> mainOrganizationsNewList=this.queryOrganizationHis(dateTime);
			//获取岗位信息增量接口
			List<MainJobsNew> mainJobsList = this.queryJobsHis(dateTime);
			//获取人员信息增量接口
			List<MainUsersNew> mainUsersNewList = this.queryUserHis(dateTime);
			
			try {
				//将信息插入到机构表及关系表
				List<OrganizationMainBean> corporationMainBeanList=new ArrayList<OrganizationMainBean>();
				for (int i = 0; i < mainOrganizationsNewList.size(); i++) {
					MainOrganizationsNew mainOrganizationsNew=new MainOrganizationsNew();
					OrganizationMainBean corporationMainBean=new OrganizationMainBean();
					mainOrganizationsNew=mainOrganizationsNewList.get(i);
					BeanUtils.copyProperties(corporationMainBean, mainOrganizationsNew);
					corporationMainBeanList.add(corporationMainBean);
				}
				organizationsMainService.saveOrganizationsMain(corporationMainBeanList,2);
			}catch(Exception e) {
				log.error(e.getMessage());
				HttpRequestMain.mailSend("机构信息增量接口", 3, this.getEmployeeList(), scf);
			}
			
			try {
				//将信息插入到岗位表及关系表
				List<RoleMainBean> roleMainBeanList=new ArrayList<RoleMainBean>();
				for(int i=0;i<mainJobsList.size();i++) {
					MainJobsNew  mainJobsNew=new MainJobsNew();
					RoleMainBean roleMainBean=new RoleMainBean();
					mainJobsNew=mainJobsList.get(i);
					BeanUtils.copyProperties(roleMainBean, mainJobsNew);
					roleMainBeanList.add(roleMainBean);
				}
				roleMainService.saveRoleMain(roleMainBeanList);
			}catch(Exception e) {
				log.error(e.getMessage());
				HttpRequestMain.mailSend("岗位信息增量接口", 3, this.getEmployeeList(), scf);
			}
			
			try {
				//将信息插入到人员表及关系表
				List<EmployeeMainBean> employeeMainBeanList = new ArrayList<EmployeeMainBean>();
				for (int i = 0; i < mainUsersNewList.size(); i++) {
					MainUsersNew mainUsersNew = new MainUsersNew();
					EmployeeMainBean employeeMainBean = new EmployeeMainBean(); 
					mainUsersNew = mainUsersNewList.get(i);
					BeanUtils.copyProperties(employeeMainBean, mainUsersNew);
					employeeMainBeanList.add(employeeMainBean);
				}
				employeeMainService.saveEmployeeMain(employeeMainBeanList);
			}catch(Exception e) {
				log.error(e.getMessage());
				HttpRequestMain.mailSend("员工信息增量接口", 3, this.getEmployeeList(), scf);
			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取 Token
	 * 
	 * @return
	 */
	private String getToken() {
		interfaceName = "token";
		String tokenUrl = AppConstant.MAIN_TOKEN_URL;
		// 请求地址
		String url = ip + tokenUrl;
		List<SystemConfigure> systemConfigureList = systemConfigureDao.selectByExample(new SystemConfigureExample());
		SystemConfigure systemConfigure = systemConfigureList.get(0);
		if (systemConfigure.getTokenAccess() == null) {
			updateSystemConfigure(url, systemConfigure);
		} else {
			boolean boo = ToolUtils.dateDiffHour(new Date().getTime()+ "", systemConfigure.getTokenTimestamp(),systemConfigure.getTokenDate());
			if (boo == true) {
				updateSystemConfigure(url, systemConfigure);
			}
		}
		return systemConfigure.getTokenAccess();
	}

	/**
	 * 处理返回JSON格式
	 * 
	 * @param url
	 * @param systemConfigure
	 */
	private void updateSystemConfigure(String url, SystemConfigure systemConfigure) {
		String userName=AppConstant.MAIN_TOKEN_USERNAME;
		String passWord=AppConstant.MAIN_TOKEN_PASSWORD;
		TokenBean tokenBean = new TokenBean();
		String resouceToken = HttpRequestMain.sendPost(interfaceName,0,url, null, null,userName,passWord,startDate,requestInterfaceTaskService,this.getEmployeeList(),systemConfigure);
		JSONObject jsonObject = JSONObject.fromObject(resouceToken);
		tokenBean = (TokenBean) JSONObject.toBean(jsonObject, TokenBean.class);
		if(tokenBean!=null) {
			systemConfigure.setTokenDate(tokenBean.getExpires_in());
			systemConfigure.setTokenTimestamp(tokenBean.getTimestamp());
			systemConfigure.setTokenAccess(tokenBean.getAccess_token());
			systemConfigureDao.updateByPrimaryKeySelective(systemConfigure);
		}
	}

	/**
	 * 获取人员信息接口
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 */
	private List<MainUsers> queryUser() throws IllegalAccessException, InvocationTargetException {
		String mainUserUrl = AppConstant.MAIN_USER_DATA_URL;
		// 请求地址
		String url = ip + mainUserUrl;
		String token=this.getToken();
		//定义接口名称
		interfaceName = "人员信息全量接口";
		MainQueryUsersBean queryUsers = new MainQueryUsersBean();
		String resouceuser = HttpRequestMain.sendPost(interfaceName,1, url, null, token, null,null,startDate,requestInterfaceTaskService,this.getEmployeeList(),scf);
		mainUsersService.deleteMainUsers();
		if (resouceuser != null) {
			JSONObject jsonObject = JSONObject.fromObject(resouceuser);
			JSONArray jsonArray = (JSONArray) jsonObject.get("result");
			if(jsonArray!=null) {
				@SuppressWarnings({ "unchecked", "static-access" })
				List<MainQueryUsersBean> resultList = (List<MainQueryUsersBean>) jsonArray.toCollection(jsonArray,MainQueryUsersBean.class);
				List<MainUsers> mainUsersList = new ArrayList<MainUsers>();
				if (resultList.size()!=0) {
					for (int i = 0; i < resultList.size(); i++) {
						MainUsers mainUsers = new MainUsers();
						queryUsers = resultList.get(i);
						BeanUtils.copyProperties(mainUsers, queryUsers);
						mainUsersList.add(mainUsers);
					}
					mainUsersService.saveMainUsers(mainUsersList);
				}
			}
		}
		return mainUsersService.getMainUsersList();
	}

	/**
	 * 获取人员信息增量接口
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 */
	private List<MainUsersNew> queryUserHis(String dateTime) throws IllegalAccessException, InvocationTargetException {
		String mainUserUrl = AppConstant.MAIN_USER_NEW_URL;
		// 请求地址
		String url = ip + mainUserUrl;
		//获取参数
		JSONObject paramJs = new JSONObject();
		paramJs.put("datapoint", dateTime);
		MainQueryUsersBean queryUsers = new MainQueryUsersBean();
//		MainResponseBean mainResponseBean = new MainResponseBean();
		String token=this.getToken();
		//定义接口名称
		interfaceName = "人员信息增量接口";
		String resouceuser = HttpRequestMain.sendPost(interfaceName,2, url, paramJs, token, null,null,startDate,requestInterfaceTaskService,this.getEmployeeList(),scf);
		mainUsersNewService.deleteMainUsersNew();
		if (resouceuser != null) {
			//log.info(interfaceName+" : "+resouceuser);
			JSONObject jsonObject = JSONObject.fromObject(resouceuser);
//			mainResponseBean = (MainResponseBean) JSONObject.toBean(jsonObject, MainResponseBean.class);
			JSONArray jsonArray = (JSONArray) jsonObject.get("result");
			if(jsonArray!=null) {
				@SuppressWarnings({ "unchecked", "static-access" })
				List<MainQueryUsersBean> resultList = (List<MainQueryUsersBean>) jsonArray.toCollection(jsonArray,MainQueryUsersBean.class);
				List<MainUsersNew> mainUsersNewList = new ArrayList<MainUsersNew>();
				if(resultList.size()!=0) {
					for (int i = 0; i < resultList.size(); i++) {
						MainUsersNew mainUsersNew = new MainUsersNew();
						queryUsers = resultList.get(i);
						BeanUtils.copyProperties(mainUsersNew, queryUsers);
						mainUsersNewList.add(mainUsersNew);
					}
					mainUsersNewService.saveMainUsersNew(mainUsersNewList);
				}
			}
		}
		return mainUsersNewService.getMainUsersNewList();
	}

	/**
	 * 获取机构信息接口
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 */
	private List<MainOrganizations> queryOrganization() throws IllegalAccessException, InvocationTargetException {
		String mainOrganizationUrl = AppConstant.MAIN_ORGANIZATION_DATA_URL;
		// 请求地址
		String url = ip + mainOrganizationUrl;
		String token=this.getToken();
		//定义接口名称
		interfaceName = "机构信息全量接口";
		MainQueryOrganizationsBean mainQueryOrganization = new MainQueryOrganizationsBean();
		String resouceOrganizations = HttpRequestMain.sendPost(interfaceName, 1,url, null, token,null,null,startDate,requestInterfaceTaskService,this.getEmployeeList(),scf);
		mainOrganizationsService.deleteMainOrganizations();
		if (resouceOrganizations != null) {
			log.info(interfaceName+" : "+resouceOrganizations);
			JSONObject jsonObject = JSONObject.fromObject(resouceOrganizations);
			JSONArray jsonArray = (JSONArray) jsonObject.get("result");
			if(jsonArray!=null) {
				@SuppressWarnings({ "unchecked", "static-access" })
				List<MainQueryOrganizationsBean> resultList = (List<MainQueryOrganizationsBean>) jsonArray.toCollection(jsonArray,MainQueryOrganizationsBean.class);
				List<MainOrganizations> mainOrganizationsList = new ArrayList<MainOrganizations>();
				if(resultList.size()!=0) {
					for (int i = 0; i < resultList.size(); i++) {
						MainOrganizations mainOrganizations = new MainOrganizations();
						mainQueryOrganization = resultList.get(i);
						BeanUtils.copyProperties(mainOrganizations, mainQueryOrganization);
						mainOrganizationsList.add(mainOrganizations);
					}
					mainOrganizationsService.saveMainOrganizations(mainOrganizationsList);
				}
			}
		}
		return mainOrganizationsService.getMainOrganizationsList();
	}
	
	/**
	 * 获取机构新增信息接口
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 */
	private List<MainOrganizationsNew> queryOrganizationHis(String dateTime) throws IllegalAccessException, InvocationTargetException {
		String mainOrganizationUrl = AppConstant.MAIN_ORGANIZATION_NEW_URL;
		// 请求地址
		String url = ip + mainOrganizationUrl;
		//获取参数
		JSONObject paramJs = new JSONObject();
		paramJs.put("datapoint", dateTime);
		String token=this.getToken();
		//定义接口名称
		interfaceName="机构信息增量接口";
		MainQueryOrganizationsBean mainQueryOrganization = new MainQueryOrganizationsBean();
		String resouceOrganizations = HttpRequestMain.sendPost(interfaceName,2,url, paramJs, token,null,null,startDate,requestInterfaceTaskService,this.getEmployeeList(),scf);
		mainOrganizationsNewService.deleteMainOrganizationsNew();
		if (resouceOrganizations != null) {
			log.info(interfaceName+" : "+resouceOrganizations);
			JSONObject jsonObject=JSONObject.fromObject(resouceOrganizations);
			JSONArray jsonArray=(JSONArray)jsonObject.get("result");
			if(jsonArray!=null) {
				@SuppressWarnings({ "unchecked", "static-access" })
				List<MainQueryOrganizationsBean> resultList=(List<MainQueryOrganizationsBean>)jsonArray.toCollection(jsonArray, MainQueryOrganizationsBean.class);
				List<MainOrganizationsNew> mainOrganizationsNewList = new ArrayList<MainOrganizationsNew>();
				if(resultList.size()!=0) {
					for (int i = 0; i < resultList.size(); i++) {
						MainOrganizationsNew mainOrganizationsNew= new MainOrganizationsNew();
						mainQueryOrganization=resultList.get(i);
						BeanUtils.copyProperties(mainOrganizationsNew, mainQueryOrganization);
						mainOrganizationsNewList.add(mainOrganizationsNew);
					}
					mainOrganizationsNewService.saveMainOrganizationsNew(mainOrganizationsNewList);
				}
			}
		}
		return mainOrganizationsNewService.getMainOrganizationsNewList();
	}
	
	/**
	 * 岗位信息接口
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 */
	private List<MainJobs> queryJobs() throws IllegalAccessException, InvocationTargetException {
		String mainJobsUrl = AppConstant.MAIN_JOBS_DATA_URL;
		// 请求地址
		String url = ip + mainJobsUrl;
		String token=this.getToken();
		//定义接口名称
		interfaceName = "岗位信息全量接口";
		MainQueryJobsBean mainQueryJobs = new MainQueryJobsBean();
		String resouceJobs = HttpRequestMain.sendPost(interfaceName, 1,url, null, token, null,null,startDate,requestInterfaceTaskService,this.getEmployeeList(),scf);
		mainJobsService.deleteMainJobs();
		if (resouceJobs != null) {
			log.info(interfaceName+" : "+resouceJobs);
			JSONObject jsonObject = JSONObject.fromObject(resouceJobs);
			JSONArray jsonArray = (JSONArray) jsonObject.get("result");
			if(jsonArray!=null) {
				@SuppressWarnings({ "unchecked", "static-access" })
				List<MainQueryJobsBean> resultList = (List<MainQueryJobsBean>) jsonArray.toCollection(jsonArray, MainQueryJobsBean.class);
				List<MainJobs> mainJobsList = new ArrayList<MainJobs>();
				if(resultList.size()!=0) {
					for (int i = 0; i < resultList.size(); i++) {
						MainJobs mainJobs = new MainJobs();
						mainQueryJobs = resultList.get(i);
						BeanUtils.copyProperties(mainJobs, mainQueryJobs);
						mainJobsList.add(mainJobs);
					}
					mainJobsService.saveMainJobs(mainJobsList);
				}
			}
		}
		return mainJobsService.getMainJobsList();
	}

	/**
	 * 岗位信息增量接口
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 */
	private List<MainJobsNew> queryJobsHis(String dateTime) throws IllegalAccessException, InvocationTargetException {
		String mainJobsUrl = AppConstant.MAIN_JOBS_NEW_URL;
		// 请求地址
		String url = ip + mainJobsUrl;
		//获取参数
		JSONObject paramJs = new JSONObject();
		paramJs.put("datapoint", dateTime);
		String token=this.getToken();
		//定义接口数据
		interfaceName = "岗位信息增量接口";
		MainQueryJobsBean mainQueryJobs = new MainQueryJobsBean();
//		MainResponseBean mainResponseBean = new MainResponseBean();
		String resouceJobs = HttpRequestMain.sendPost(interfaceName,2,url, paramJs, token,null,null, startDate,requestInterfaceTaskService,this.getEmployeeList(),scf);
		mainJobsNewService.deleteMainJobsNew();
		if (resouceJobs != null) {
			log.info(interfaceName+" : "+resouceJobs);
			JSONObject jsonObject = JSONObject.fromObject(resouceJobs);
//			mainResponseBean = (MainResponseBean) JSONObject.toBean(jsonObject, MainResponseBean.class);
			JSONArray jsonArray = (JSONArray) jsonObject.get("result");
			if(jsonArray!=null) {
				@SuppressWarnings({ "unchecked", "static-access" })
				List<MainQueryJobsBean> resultList = (List<MainQueryJobsBean>) jsonArray.toCollection(jsonArray, MainQueryJobsBean.class);
				List<MainJobsNew> mainJobsNewList = new ArrayList<MainJobsNew>();
				if(resultList.size()!=0) {
					for (int i = 0; i < resultList.size(); i++) {
						MainJobsNew mainJobsNew = new MainJobsNew();
						mainQueryJobs = resultList.get(i);
						BeanUtils.copyProperties(mainJobsNew, mainQueryJobs);
						mainJobsNewList.add(mainJobsNew);
					}
					mainJobsNewService.saveMainJobsNew(mainJobsNewList);
				}
			}
		}
		return mainJobsNewService.getMainJobsNewList();
	}
	
	/**
	 * 获取发送邮箱人员
	 * @return
	 */
	private List<Employee> getEmployeeList() {
		List<Employee> employeeList=new ArrayList<Employee>();
		if(StringUtils.isNotBlank(mailEmployeeNo)) {
			String[] employeeNoList=mailEmployeeNo.split(",");
			for(int i=0;i<employeeNoList.length;i++) {
				EmployeeExample employeeExample=new EmployeeExample();
				employeeExample.createCriteria().andEmployeeNoEqualTo(employeeNoList[i]);
				List<Employee> empList=employeeDao.selectByExample(employeeExample);
				if(empList.size()>0) {
					employeeList.add(empList.get(0));
				}
			}
		}	
		return employeeList;
	}
}
